package br.com.imob.modelo;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Gilton Nascimento
 */
@Entity
@Table(name = "\"CONTATO\"", catalog = "imob", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Contato.findAll", query = "SELECT c FROM Contato c"),
    @NamedQuery(name = "Contato.findByContatoId", query = "SELECT c FROM Contato c WHERE c.contatoId = :contatoId"),
    
    @NamedQuery(name = "Contato.findByTelefone", query = "SELECT c FROM Contato c WHERE c.telefone = :telefone"),
    @NamedQuery(name = "Contato.findLikeByTelefone", query = "SELECT c FROM Contato c WHERE c.telefone Like :telefone"),
    
    @NamedQuery(name = "Contato.findByComercial", query = "SELECT c FROM Contato c WHERE c.comercial = :comercial"),
    @NamedQuery(name = "Contato.findLikeByComercial", query = "SELECT c FROM Contato c WHERE c.comercial Like :comercial"),
    
    @NamedQuery(name = "Contato.findByCelular", query = "SELECT c FROM Contato c WHERE c.celular = :celular"),
    @NamedQuery(name = "Contato.findLikeByCelular", query = "SELECT c FROM Contato c WHERE c.celular Like :celular"),
    
    @NamedQuery(name = "Contato.findByFax", query = "SELECT c FROM Contato c WHERE c.fax = :fax"),
    @NamedQuery(name = "Contato.findLikeByFax", query = "SELECT c FROM Contato c WHERE c.fax Like :fax")
    })
public class Contato implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
//  <editor-fold defaultstate="collapsed" desc="Geradores de Sequencias">
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
    @SequenceGenerator(name = "SEQ_STORE", sequenceName = "next_contato")// </editor-fold>
    @Basic(optional = false)
    @Column(name = "contato_id", nullable = false)
    private Integer contatoId;
    
    @Column(name = "telefone", length = 15)
    private String telefone;
    
    @Column(name = "comercial", length = 20)
    private String comercial;
    
    @Column(name = "celular", length = 15)
    private String celular;
    
    @Column(name = "fax", length = 25)
    private String fax;
    
    @OneToMany(mappedBy = "contato", fetch = FetchType.LAZY)
    private List<Empresa> empresaList;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contato1", fetch = FetchType.LAZY)
    private List<Empresa> empresaList1;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contato", fetch = FetchType.LAZY)
    private List<Pessoa> pessoaList;
    
    @OneToMany(mappedBy = "contato", fetch = FetchType.LAZY)
    private List<Corretor> corretorList;
    
    @OneToMany(mappedBy = "contato", fetch = FetchType.LAZY)
    private List<Construtora> construtoraList;

    public Contato() {
    }

    public Contato(Integer contatoId) {
        this.contatoId = contatoId;
    }

    public Contato(String fone) { telefone = fone; }
    
    public Contato(String fone, String cell) { 
    	this(fone);
    	celular = cell;
	}
    
    public Contato(String fone, String cell, String comerc) { 
    	this(fone, cell);
    	comercial = comerc;
    }
    
    public Contato(String fone, String cell, String comerc, String fx) { 
    	this(fone, cell, comerc);
    	fax = fx;
    }
    
    public Contato(int id, String tpStr, String arg) {
    	contatoId = id;
    	if("telefone".equalsIgnoreCase(tpStr))
    		telefone = arg;
    	if("celular".equalsIgnoreCase(tpStr))
    		celular = arg;
    	if("comercial".equalsIgnoreCase(tpStr))
    		comercial = arg;
    	if("fax".equalsIgnoreCase(tpStr))
    		fax = arg;
    }

    

	//    Getts and Setts
	public Integer getContatoId() {
        return contatoId;
    }

    public void setContatoId(Integer contatoId) {
        this.contatoId = contatoId;
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }

    public String getComercial() {
        return comercial;
    }

    public void setComercial(String comercial) {
        this.comercial = comercial;
    }

    public String getCelular() {
        return celular;
    }

    public void setCelular(String celular) {
        this.celular = celular;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public List<Empresa> getEmpresaList() {
        return empresaList;
    }

    public void setEmpresaList(List<Empresa> empresaList) {
        this.empresaList = empresaList;
    }

    public List<Empresa> getEmpresaList1() {
        return empresaList1;
    }

    public void setEmpresaList1(List<Empresa> empresaList1) {
        this.empresaList1 = empresaList1;
    }

    public List<Pessoa> getPessoaList() {
        return pessoaList;
    }

    public void setPessoaList(List<Pessoa> pessoaList) {
        this.pessoaList = pessoaList;
    }

    public List<Corretor> getCorretorList() {
        return corretorList;
    }

    public void setCorretorList(List<Corretor> corretorList) {
        this.corretorList = corretorList;
    }

    public List<Construtora> getConstrutoraList() {
        return construtoraList;
    }

    public void setConstrutoraList(List<Construtora> construtoraList) {
        this.construtoraList = construtoraList;
    }

    public Object[] getValues() {
    	Object[] objects = {contatoId, telefone, celular, comercial, fax};
    	return objects; 
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (contatoId != null ? contatoId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Contato)) {
            return false;
        }
        Contato other = (Contato) object;
        if ((this.contatoId == null && other.contatoId != null) || (this.contatoId != null && !this.contatoId.equals(other.contatoId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.imob.modelo.Contato[contatoId=" + contatoId + "]";
    }

}
